function ajax(url, param, type) {
	// 利用了jquery延迟对象回调的方式对ajax封装，使用done()，fail()，always()等方法进行链式回调操作
	// 如果需要的参数更多，比如有跨域dataType需要设置为'jsonp'等等，可以考虑参数设置为对象
	return $.ajax({
		url: url,
		beforeSend: function(xhr) {
			// xhr.setRequestHeader("user-token", '88888888888888888888888888888888');
			xhr.setRequestHeader("user-token", $.cookie('token'));
		},
		data: param || {},
		type: type || 'GET',
		success: function(res) {
			if(res.code == 102) {
				Err(res.msg)
				window.location.href = '/html/login/index.html'
			}
		}
	});
}
//将对象中的对象里面的每条属性拿到对象外面来
function objdetail(obj){
	var obj2={};
	for(var key in obj){
		if( typeof obj[key] === 'object'){
			obj2[key]=obj[key]
			if(!(obj[key] instanceof Array)){
				for(var key2 in obj[key]){
					obj2[key2]=obj[key][key2]
				}
			}else{
				obj2[key]=obj[key]
			}
		}else{
			obj2[key]=obj[key]
		}
	}
	return obj2
}

//订单状态转换
function orderstate(res) {
	if(res.data){
	for(var i = 0; i < res.data.length; i++) {
		if(res.data[i].order_type) {
			if(res.data[i].order_type == 1) {
				res.data[i].order_type2 = '公务订单'
			} else if(res.data[i].order_type == 2) {
				res.data[i].order_type2 = '企业订单'
			} else if(res.data[i].order_type == 3) {
				res.data[i].order_type2 = '个人订单'
			}
		}
		if(res.data[i].order_state) {
			if(res.data[i].order_state == 1) {
				res.data[i].order_state2 = '待审批'
			} else if(res.data[i].order_state == 2) {
				res.data[i].order_state2 = '已批准'
			} else if(res.data[i].order_state == 3) {
				res.data[i].order_state2 = '已拒绝'
			} else if(res.data[i].order_state == 4) {
				res.data[i].order_state2 = '待用车'
			} else if(res.data[i].order_state == 5) {
				res.data[i].order_state2 = '已派车'
			} else if(res.data[i].order_state == 6) {
				res.data[i].order_state2 = '接驾中'
			} else if(res.data[i].order_state == 7) {
				res.data[i].order_state2 = '已到达出发地'
			} else if(res.data[i].order_state == 8) {
				res.data[i].order_state2 = '已到达目的地'
			} else if(res.data[i].order_state == 9) {
				res.data[i].order_state2 = '待支付'
			} else if(res.data[i].order_state == 10) {
				res.data[i].order_state2 = '待评价'
			} else if(res.data[i].order_state == 11) {
				res.data[i].order_state2 = '已完成'
			} else if(res.data[i].order_state == 12) {
				res.data[i].order_state2 = '已取消'
			} else if(res.data[i].order_state == 13) {
				res.data[i].order_state2 = '已终止'
			} else if(res.data[i].order_state == 14) {
				res.data[i].order_state2 = '无效'
			}
		}

		if(res.data[i].use_type) {
			if(res.data[i].use_type == 1) {
				res.data[i].use_type2 = '行政执法'
			} else if(res.data[i].use_type == 2) {
				res.data[i].use_type2 = '特殊公务'
			} else if(res.data[i].use_type == 3) {
				res.data[i].use_type2 = '重要会议'
			} else if(res.data[i].use_type == 4) {
				res.data[i].use_type2 = '机要通讯'
			} else if(res.data[i].use_type == 5) {
				res.data[i].use_type2 = '视察调研'
			} else if(res.data[i].use_type == 6) {
				res.data[i].use_type2 = '公务接待'
			} else if(res.data[i].use_type == 7) {
				res.data[i].use_type2 = '应急公务'
			} else if(res.data[i].use_type == 8) {
				res.data[i].use_type2 = '紧急就医'
			}
		}
	}
	}
	return res
}
function Msg(msg, func) {
	layer.msg(msg, {
		icon: 1
	}, func);
}

function Err(msg) {
	layer.msg(msg, {
		icon: 2
	});
}
function Load(close,loadname) {
	var load;
	if(close) {
		layer.closeAll('loading');
	} else {
		load=layer.load(0, {
			shade: false,
		});
	}
};
//根据id查找列表中的相符的数据
function getdetail(id,res,id_name){
	for(var i=0;i<res.length;i++){
		if(res[i][id_name]==id){
			return res[i]
		}
	}
}
function exports(res,tddata,data,url){
	var getkey="";
	for(var iii=0;iii<tddata.length;iii++){
		for(var key in res.description){
			if(key==tddata[iii].key){
				tddata[iii].text=res.description[key].name
			}
		}
		getkey+=`<li>
				<label class="am-checkbox">
			      <input type="checkbox" value="" data-key='${tddata[iii].key}' checked> ${tddata[iii].text}
			    </label>
			</li>`
	}
	let layerIndex = layer.open({
	  	type: 1,
	  	title:false,
	  	skin: 'layui-layer-rim', //加上边框
	  	area: ['300px', '400px'], //宽高
	  	content: `<div>
	 				<div style='height:300px;overflow:auto;margin-bottom:30px'>
				  	<ul class='daochuul'>${getkey}</ul>
				  	</div>
				  	<div style='text-align:center'>
				  		<button class='am-btn am-btn-sm am-btn-primary am-radius daochu_ok' type='button'>确定导出</button>
				  		<button class='am-btn am-btn-sm am-btn-primary am-radius export-cancel' type='button'>取消</button>
				  	</div>
				</div>`,
		success:function(){
			var ddata={
				fields:''
			}
			$('.daochu_ok').on('click',function(){
				$('.daochuul li input[type="checkbox"]').each(function(){
					if(this.checked){
						ddata.fields+=($(this).data('key')+",")
					}
				})
				ddata.fields=ddata.fields.slice(0,ddata.fields.length-1)

				setTimeout(function(){
                    layer.close(layerIndex);
				}, 500);

				window.open(`${url}?where_json=${data.where_json}&fields=${ddata.fields}`)
//								
			})

			$('.export-cancel').on('click', function(){
                layer.close(layerIndex);
			});
			
		}
	});
}
function driverstate(res) {
	console.log('xingbie')
if(res.data){
	for(var i = 0; i < res.data.length; i++) {
		if(res.data[i].work_state) {
			if(res.data[i].work_state == 1) {
				res.data[i].work_state2 = '执行任务中'
			} else if(res.data[i].work_state == 2) {
				res.data[i].work_state2 = '有预约订单'
			} else if(res.data[i].work_state == 3) {
				res.data[i].work_state2 = '听单中'
			} else {
				res.data[i].work_state2 = '下班'
			}
		}else{
			res.data[i].work_state2 = null
		}
		
		if(res.data[i].state) {
			if(res.data[i].state == 1) {
				res.data[i].state2 = '启用'
			} else {
				res.data[i].state2 = '禁用'
			}
		}else{
			res.data[i].state2 = null
		}

		if(res.data[i].sex){
			 
			if(res.data[i].sex == 1) {
				res.data[i].sex2 = '男'
			} else {
				res.data[i].sex2 = '女'
			}
		}else{
			res.data[i].sex2 = null
		}
	}
	}
	return res
}


function passengerstate(res) {
	if(res.data){
	for(var i = 0; i < res.data.length; i++) {
		if(res.data[i].is_check) {
			if(res.data[i].is_check == 1) {
				res.data[i].is_check2 = '审核员'
			} else {
				res.data[i].is_check2 = '非审核员'
			}
		}
		if(res.data[i].sex) {
			if(res.data[i].sex == 1) {
				res.data[i].sex2 = '女'
			} else {
				res.data[i].sex2 = '男'
			}
		}
	}
	}
	return res
}

function jsonchange(val) {
	return JSON.stringify(val)
}

function opsearch(url,type,title) {
	var area=[]
	if(type == 1) {
		area=['40%','40%']
	} else if(type == 2) {
		area=['60%','60%']
	} else {
		area=['80%','80%']
	}
	layer.open({
	  type: 2,
	  title: title||'请选择',
	  shadeClose: true,
	  shade: 0.8,
	  area: area,
	  content: url //iframe的url
	}); 
	
}
function gototitle(title,url){
	Msg(title)
	setTimeout(function(){
		window.location.href=url
	},1000)
}

function carinfo(res) {
	if(res.list){
	for(var i = 0; i < res.list.length; i++) {
		if(res.list[i].car_state) {
			if(res.list[i].car_state == 1) {
				res.list[i].car_state2 = '执行任务中'
			} else if(res.list[i].car_state == 2) {
				res.list[i].car_state2 = '空闲'
			} else{
				res.list[i].car_state2 = null
			}
		}else{
			res.list[i].car_state2 = null
		}
		if(res.list[i].gearbox_type) {
			if(res.list[i].state == 1) {
				res.list[i].gearbox_type2 = '手动'
			} else if(res.list[i].state == 2){
				res.list[i].gearbox_type2 = '自动'
			}else if(res.list[i].state == 3){
				res.list[i].gearbox_type2 = '手自一体'
			}else{
				res.list[i].gearbox_type2 = null
			}
		}else{
			res.list[i].gearbox_type2 = null
		}
		if(res.list[i].source){
			if(res.list[i].source == 0){
				res.list[i].source2 ='单位直属公务车'
			}else if(res.list[i].source == 1){
				res.list[i].source2 ='管理公司直属公务车'
			}else if(res.list[i].source == 2){
				res.list[i].source2 ='单位自有车辆'
			}else{
				res.list[i].source2 =null
			}
		}else{
			res.list[i].source2 =null
		}
		if(res.list[i].state) {
			if(res.list[i].state == 1) {
				res.list[i].state2 = '启用'
			} else if(res.list[i].state == 9){
				res.list[i].state2 = '禁用'
			}else if(res.list[i].state == 6){
				res.list[i].state2 = '待入库'
			}else if(res.list[i].state == 7){
				res.list[i].state2 = '拍卖'
			}else if(res.list[i].state == 8){
				res.list[i].state2 = '报废'
			}else{
				res.list[i].state2 = null
			}
		}else{
			res.list[i].state2 = null
		}
		
		if(res.list[i].structure){
			if(res.list[i].structure == 1){
				res.list[i].structure2 ='两厢车'
			}else if(res.list[i].structure == 2){
				res.list[i].structure2 ='三厢车'
			}else if(res.list[i].structure == 3){
				res.list[i].structure2 ='SUV'
			}else{
				res.list[i].structure2 =null
			}
		}else{
			res.list[i].structure2 =null
		}
		if(res.list[i].energy_type){
			if(res.list[i].energy_type == 1){
				res.list[i].energy_type2 ='电动'
			}else if(res.list[i].energy_type == 2){
				res.list[i].energy_type2 ='汽油'
			}else if(res.list[i].energy_typee == 3){
				res.list[i].energy_type2 ='柴油'
			}else{
				res.list[i].energy_type2 =null 

			}
		}else{
			res.list[i].energy_type2 =null 
		}
	}
	}
	return res
}
function menuhtml(obj){
	let menu_html=``;
	for(var i=0;i<obj.length;i++){
		if(obj[i].name=='system'){
			obj[i].name='系统设置'
		}else if(obj[i].name=='stat'){
			obj[i].name='统计管理'
		}else if(obj[i].name=='plus'){
			obj[i].name='公务用车管理'
		}else if(obj[i].name=='order'){
			obj[i].name='公务用车调度管理'
		}else if(obj[i].name=='index'){
			obj[i].name='首页'
		}else if(obj[i].name=='finace'){
			obj[i].name='经费管理'
		}else if(obj[i].name=='car'){
			obj[i].name='用车配备管理'
		}else if(obj[i].name=='beidou'){
			obj[i].name='北斗定位'
		}
		menu_html+=`<li class="layui-nav-item">
						<a class="" href="javascript:;">${obj[i].name}</a>
						<dl class="layui-nav-child">`
		for(var i2=0;i2<obj[i].children.length;i2++){
			menu_html+=`<dd><a href="${obj[i].children[i2].url}">${obj[i].children[i2].name}</a></dd>`
		}
		menu_html+=`		</dl>
					</li>`
	}
	return menu_html
}
